#include "TimeSys.h"
#include <cstdio>

TimeSys::TimeSys() {
    originT = { 1970, 1, 1, 0, 0, 0, 0.0 };
}

BaseT TimeSys::calend2baseT(CalendT t0) {
    BaseT base;
    base.sec = t0.hour * 3600 + t0.min * 60 + t0.sec;
    base.sesec = t0.sesec;
    return base;
}

BaseT TimeSys::str2baseT(const std::string& t) {
    CalendT cal;
    sscanf(t.c_str(), "%d %d %d %d %d %lf",
        &cal.year, &cal.month, &cal.day,
        &cal.hour, &cal.min, &cal.sesec);
    cal.sec = static_cast<int>(cal.sesec);
    cal.sesec -= cal.sec;
    return calend2baseT(cal);
}